home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method="html" encoding="ISO-8859-1" indent="yes"/>
-
- <xsl:key name="teams" match="result/home" use="@team"/>
- <xsl:key name="teams" match="result/away" use="@team"/>
- <xsl:key name="opposition" match="result/home" use="../away/@team"/>
- <xsl:key name="opposition" match="result/away" use="../home/@team"/>
- <xsl:key name="wins" match="result/away[@score > ../home/@score]" use="@team"/>
- <xsl:key name="wins" match="result/home[@score > ../away/@score]" use="@team"/>
- <xsl:key name="draws" match="result/away[@score = ../home/@score]" use="@team"/>
- <xsl:key name="draws" match="result/home[@score = ../away/@score]" use="@team"/>
- <!-- keys used to calc home/away results specifically -->
- <xsl:key name="home-teams" match="result/home" use="@team"/>
- <xsl:key name="home-opposition" match="result/away" use="../home/@team"/>
- <xsl:key name="home-wins" match="result/home[@score > ../away/@score]" use="@team"/>
- <xsl:key name="home-draws" match="result/home[@score = ../away/@score]" use="@team"/>
-
- <xsl:template match="/">
- <html>
- <head>
- <title>
- <xsl:value-of select="/results/@nation"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="/results/@sponsor"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="/results/@league"/>
- <xsl:text> (full home/away)</xsl:text>
- </title>
- </head>
- <body>
- <h3>
- <xsl:value-of select="/results/@nation"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="/results/@sponsor"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="/results/@league"/>
- <xsl:text> (full home/away)</xsl:text>
- </h3>
- <table border="0" bgcolor="Black" cellspacing="1" style="font-family: Courier New, Courier, monospace; font-size: 12;">
- <tr bgcolor="Silver">
- <th rowspan="2" valign="bottom">Pos</th>
- <th rowspan="2" valign="bottom">Team</th>
- <th rowspan="2" valign="bottom">Pld</th>
- <th colspan="5" align="center">Home</th>
- <th colspan="5" align="center">Away</th>
- <th colspan="5" align="center">Overall</th>
- <th width="20" rowspan="2" valign="bottom">GD</th>
- <th width="20" rowspan="2" valign="bottom">Pts</th>
- </tr>
- <tr bgcolor="Silver">
- <!-- Home record -->
- <th width="20">W</th>
- <th width="20">D</th>
- <th width="20">L</th>
- <th width="20">F</th>
- <th width="20">A</th>
- <!-- Away record -->
- <th width="20">W</th>
- <th width="20">D</th>
- <th width="20">L</th>
- <th width="20">F</th>
- <th width="20">A</th>
- <!-- Overall record -->
- <th width="20">W</th>
- <th width="20">D</th>
- <th width="20">L</th>
- <th width="20">F</th>
- <th width="20">A</th>
- </tr>
- <!-- apply template to each distinct team -->
- <xsl:apply-templates select="(/results/result/home|/results/result/away)[generate-id(.) = generate-id(key('teams',@team))]">
- <!-- sort primarily on points -->
- <xsl:sort select="(count(key('wins',@team)) * 3) + (count(key('draws',@team)))" data-type="number" order="descending"/>
- <!-- secondary sort by goal difference -->
- <xsl:sort select="sum(key('teams',@team)/@score) - sum(key('opposition',@team)/@score)" data-type="number" order="descending"/>
- <!-- final sort on goals scored -->
- <xsl:sort select="sum(key('teams',@team)/@score)" data-type="number" order="descending"/>
- </xsl:apply-templates>
- </table>
- <sub>
- <xsl:text>(Results up to and including </xsl:text>
- <!-- find max date - don't rely on results being sorted -->
- <xsl:variable name="last-date">
- <xsl:apply-templates select="/results/result/@date[1]" mode="find-max">
- <xsl:sort select="translate(.,'-','')" data-type="number" order="ascending"/>
- </xsl:apply-templates>
- </xsl:variable>
- <xsl:value-of select="concat(substring($last-date,9,2),'/',substring($last-date,6,2),'/',substring($last-date,1,4))"/>
- <xsl:text>)</xsl:text>
- </sub>
- </body>
- </html>
- </xsl:template>
-
- <xsl:template match="home|away">
- <!-- store any nodesets used more than once -->
- <xsl:variable name="games" select="key('teams',@team)"/>
- <xsl:variable name="home-games" select="key('home-teams',@team)"/>
- <!-- calculate anything that is used more than once -->
- <!-- saves processing keys excessively -->
- <xsl:variable name="played" select="count($games)"/>
- <xsl:variable name="wins" select="count(key('wins',@team))"/>
- <xsl:variable name="draws" select="count(key('draws',@team))"/>
- <xsl:variable name="goals-for" select="sum($games/@score)"/>
- <xsl:variable name="goals-against" select="sum(key('opposition',@team)/@score)"/>
- <!-- home record calcs -->
- <xsl:variable name="home-played" select="count($home-games)"/>
- <xsl:variable name="home-wins" select="count(key('home-wins',@team))"/>
- <xsl:variable name="home-draws" select="count(key('home-draws',@team))"/>
- <xsl:variable name="home-goals-for" select="sum($home-games/@score)"/>
- <xsl:variable name="home-goals-against" select="sum(key('home-opposition',@team)/@score)"/>
- <!-- away record calcs -->
- <xsl:variable name="away-played" select="$played - $home-played"/>
- <xsl:variable name="away-wins" select="$wins - $home-wins"/>
- <xsl:variable name="away-draws" select="$draws - $home-draws"/>
- <xsl:variable name="away-goals-for" select="$goals-for - $home-goals-for"/>
- <xsl:variable name="away-goals-against" select="$goals-against - $home-goals-against"/>
- <!-- pre-calc cross row/col colour -->
- <xsl:variable name="cross-colour" select="substring('E0E0E023E2A9',((position() mod 2)*6)+1,6)"/>
- <!-- now display the table row -->
- <tr bgcolor="#{substring('FFFFFF8AF7D6',((position() mod 2)*6)+1,6)}">
- <!-- league position -->
- <td align="right"><xsl:value-of select="position()"/></td>
- <!-- team name -->
- <td><xsl:value-of select="@team"/></td>
- <!-- games played -->
- <td align="right"><xsl:value-of select="$played"/></td>
- <!-- HOME RECORD -->
- <!-- wins -->
- <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$home-wins"/></td>
- <!-- draws -->
- <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$home-draws"/></td>
- <!-- losses -->
- <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$home-played - $home-wins - $home-draws"/></td>
- <!-- goals for -->
- <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$home-goals-for"/></td>
- <!-- goals against -->
- <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$home-goals-against"/></td>
- <!-- AWAY RECORD -->
- <!-- wins -->
- <td align="right"><xsl:value-of select="$away-wins"/></td>
- <!-- draws -->
- <td align="right"><xsl:value-of select="$away-draws"/></td>
- <!-- losses -->
- <td align="right"><xsl:value-of select="$away-played - $away-wins - $away-draws"/></td>
- <!-- goals for -->
- <td align="right"><xsl:value-of select="$away-goals-for"/></td>
- <!-- goals against -->
- <td align="right"><xsl:value-of select="$away-goals-against"/></td>
- <!-- OVERALL RECORD -->
- <!-- wins -->
- <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$wins"/></td>
- <!-- draws -->
- <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$draws"/></td>
- <!-- losses -->
- <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$played - $wins - $draws"/></td>
- <!-- goals for -->
- <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$goals-for"/></td>
- <!-- goals against -->
- <td align="right" bgcolor="#{$cross-colour}"><xsl:value-of select="$goals-against"/></td>
- <!-- goal difference -->
- <td align="right"><xsl:value-of select="$goals-for - $goals-against"/></td>
- <!-- points -->
- <td align="right"><xsl:value-of select="($wins * 3) + $draws"/></td>
- </tr>
- </xsl:template>
-
- <xsl:template match="@date" mode="find-max">
- <xsl:if test="position() = last()">
- <xsl:value-of select="."/>
- </xsl:if>
- </xsl:template>
-
- </xsl:stylesheet>